<?php

global $_W, $_GPC;
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if ($operation == 'display') {
    ca('order.view');
    $paytype = array('wechat' => array('css' => 'success', 'name' => '微信支付'), 'unionpay' => array('css' => 'warning', 'name' => '银联支付')); //支付方式
    $condition = " r.status=1 and r.uniacid = :uniacid ";
    $paras = array(':uniacid' => $_W['uniacid']);
    $starttime = empty($_GPC['time']['start']) ? strtotime('-1 month') : strtotime($_GPC['time']['start']);
    $endtime = empty($_GPC['time']['end']) ? time() : strtotime($_GPC['time']['end']);
    if ($_GPC['searchtime'] == '1') {
        $condition .= " AND r.paytime >= :starttime AND r.paytime <= :endtime ";
        $paras[':starttime'] = $starttime;
        $paras[':endtime'] = $endtime;
    }
    if (!empty($_GPC['ordersn'])) {
        $condition.=" and r.ordersn=:ordersn ";
        $paras[':ordersn'] = trim($_GPC['ordersn']);
    }
    if (!empty($_GPC['paytype'])) {
        $condition.=" and l.type=:type ";
        $paras[':type'] = trim($_GPC['paytype']);
    }
    if (!empty($_GPC['member'])) {
        $_GPC['member'] = trim($_GPC['member']);
        $condition .= " AND (m.realname LIKE '%{$_GPC['member']}%' or m.nickname LIKE '%{$_GPC['member']}%' or m.mobile LIKE '%{$_GPC['member']}%')";
    }
    $record = pdo_fetchAll("SELECT m.realname,m.avatar,m.nickname,m.mobile,m.weixin,m.company,m.gender,m.province,m.city,m.area,r.paytime,l.tid,l.type,l.fee,r.experienceid,r.createtime  FROM " . tablename('ewei_shop_commission_experience_paylog') . " l left  join " . tablename('ewei_shop_member') . " m on l.openid=m.uid and l.uniacid=m.uniacid" . " left join" . tablename("ewei_shop_commission_experience_record") . "as r on r.ordersn=l.tid and r.status=l.status  WHERE  $condition order by r.id desc", $paras);
    foreach ($record as $key => $value) {
        $record[$key]['paytime'] = date('Y-m-d H:i:s', $value['paytime']);
    }
    if ($_GPC['export'] == 1) {
        ca('order.op.export');
        foreach ($record as $key => $value) {
            $experienceinfo = pdo_fetch("SELECT *  FROM " . tablename('ewei_shop_commission_experience') . " WHERE id =:id ", array(':id' => $value['experienceid']));
            $record[$key]['title'] = $experienceinfo['title'];
            $record[$key]["saomatime"] = date('Y-m-d H:i:s', $value['createtime']);
            $record[$key]["gender"] = $value['gender'] == 1 ? "男" : "女";
            $record[$key]["isuse"] = $value['status'] == 0 ? "未使用" : "已使用";
            $record[$key]["address"] = $value['province'] . ' ' . $value['city'] . '' . $value['area'];
        }
        $columns = array(
            array('title' => '昵称', 'field' => 'nickname', 'width' => 12),
            array('title' => '姓名', 'field' => 'realname', 'width' => 12),
            array('title' => '手机号码', 'field' => 'mobile', 'width' => 12),
            array('title' => '微信号', 'field' => 'weixin', 'width' => 12),
            array('title' => '性别', 'field' => 'gender', 'width' => 12),
            array('title' => '所在城市', 'field' => 'address', 'width' => 12),
            array('title' => '扫码活动ID', 'field' => 'experienceid', 'width' => 12),
            array('title' => '扫码活动主题', 'field' => 'title', 'width' => 12),
            array('title' => "扫码时间", 'field' => 'saomatime', 'width' => 24),
            array('title' => '是否使用', 'field' => 'isuse', 'width' => 12)
        );
        m('excel')->export($record, array("title" => "体验券支付订单导出" . date('Y-m-d-H-i', time()), "columns" => $columns));
    }
}
load()->func('tpl');
include $this->template('web/allorder/experience_list');
